﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hi_Baidu.Packet.InPacket.TalkInPacket;
using System.Windows.Controls;
using System.Windows.Media;
using WpfApplication1;
using System.IO;
using System.Windows;
using System.Windows.Documents;
using Hi_Baidu.Notify.NotifyObject;
using System.Windows.Media.Imaging;
using Hi_Baidu.ListType.DetachImage;
using Hi_Baidu.Entry.CollectionObject;
using Hi_Baidu.User.LogEntry;
using System.Threading;

namespace Hi_Baidu.ProcessModel
{
    class ChatViewModel : Model
    {
        private static System.Timers.Timer timer_Action;
        private static Win_TalkWindow WindowShadow;
        private delegate void DELEGATE_SHADOW();
        private static int ShadowCounter = 0;

        public static void ReadTalkMessage(Total_TalkMessagePacket inpackage)
        {
            INNER_ReadTalkMessage(inpackage.GetMessage(), inpackage.GetUsername(), inpackage.TalkPackage.SendTime.ToShortTimeString(), inpackage.GetUsername(),inpackage.GetSession());
            ChatProcessModel.ACK_SucessMessage(inpackage.GetSession(), Encoding.Default.GetString(Globle.user.DIC_USERINFO["USERNAME"]), inpackage.GetUsername());
        }

        public static void ReadTalkMessage(String MessageContent, String username, String SendTime, String FriendName, String TalkSession)
        {
            INNER_ReadTalkMessage(MessageContent, username, SendTime, FriendName, TalkSession);
        }

        private static void INNER_ReadTalkMessage(String MessageContent, String username, String SendTime,String FriendName, String TalkSession)
        {
            //如果当前对应聊天窗口存在
            if (CheckChatWindowExists(username))
            {
                //2 x 1的表格
                Grid Total_Grid = new Grid();
                Total_Grid.RowDefinitions.Add(new RowDefinition());
                Total_Grid.RowDefinitions.Add(new RowDefinition());

                WrapPanel WP_UserTalkMessage = new WrapPanel();
                WP_UserTalkMessage.Margin = new Thickness(3, 3, 3, 3);
                WP_UserTalkMessage.Orientation = Orientation.Horizontal;
                Total_Grid = AppendHead(Total_Grid, username, SendTime);
                String Content = MessageContent.Replace("(*Equ*)", "=");
                String[] Contents = Content.Split(new String[] { "/>" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (String content in Contents)
                {
                    //去掉命令头标示
                    content.Replace("<", "");
                    String[] SubContents = content.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    //初始化聊天信息内容字典
                    Dictionary<String, String> DIC_TALKINFO = new Dictionary<string, string>();
                    //开始分割详细属性
                    foreach (String item in SubContents)
                    {
                        if (item.IndexOf("=") < 0)
                        {
                            DIC_TALKINFO.Add("HEAD_ATTR", item.Replace("<", ""));
                        }
                        else
                        {
                            String[] SubItems = item.Split(new String[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                            DIC_TALKINFO.Add(SubItems[0], SubItems[1]);
                        }
                    }
                    //分析当前对象类型
                    if (DIC_TALKINFO["HEAD_ATTR"] == "FONT")
                    {
                        WP_UserTalkMessage.Children.Add(ConstrueText(DIC_TALKINFO));
                    }
                    else if (DIC_TALKINFO["HEAD_ATTR"] == "PIC")
                    {
                        WP_UserTalkMessage.Children.Add(ConstrueImage(DIC_TALKINFO, TalkSession));
                    }
                }
                Total_Grid.Children.Add(WP_UserTalkMessage);
                Grid.SetRow(WP_UserTalkMessage, 1);
                AppendMessage(Total_Grid, FriendName,TalkSession);
            }
            else
            {
                //不存在则打入提示队列
                //////////////////////////////////////////////////////////////////////////////////////////////////
                ///                 开始触发任务栏图标
                ///////////////////////////////////////////////////////////////////////////////////////////////////
                Notify_TalkMessage notify_TalkMessage = new Notify_TalkMessage("TalkMessage: " + username + DateTime.Now.ToString(), username, Hi_Baidu.Notify.NotifyType.NOTIFYTYPE.TALK_MESSAGE, SendTime, MessageContent, TalkSession);
                Globle.systemNotifyIconManager.Add(notify_TalkMessage);
                Globle.systemNotifyIconManager.Start();
            }
        }

        /// <summary>
        ///     检测指定聊天窗体是否存在
        /// </summary>
        /// <param name="Key" type="string">
        ///     <para>
        ///         聊天窗口唯一标示
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回false , 表示不存在
        /// </returns>
        public static bool CheckChatWindowExists(String Key)
        {
            if(Globle.popWindowManager.GetMemberByKey(Key) == null)
            {
                return false;
            }
            return true;
        }   

        public static void AppendForMySelf(RichTextBox rtb_TalkMessage,String FriendUsername)
        {
            AppendMessage(ChatProcessModel.Construe(rtb_TalkMessage, Encoding.Default.GetString(Globle.user.DIC_USERINFO["NICKNAME"])), FriendUsername, "None");
        }

        /// <summary>
        ///     向指定聊天窗口中附加本次聊天内容
        /// </summary>
        /// <param name="Total_Grid" type="System.Windows.Controls.Grid">
        ///     <para>
        ///         聊天内容总容器
        ///     </para>
        /// </param>
        /// <param name="inpackage" type="Hi_Baidu.Packet.InPacket.TalkInPacket.Total_TalkMessagePacket">
        ///     <para>
        ///         聊天内容包
        ///     </para>
        /// </param>
        public static void AppendMessage(Grid Total_Grid, Total_TalkMessagePacket inpackage)
        {
            // 获取用户聊天窗口
            Win_TalkWindow win_TalkWindow = Globle.popWindowManager.GetMemberByKey(inpackage.GetUsername()) as Win_TalkWindow;
            //存在这添加聊天信息
            if (win_TalkWindow != null)
            {
                Total_Grid.Tag = inpackage.GetSession();
                BlockUIContainer IUC = new BlockUIContainer(Total_Grid);
                //Paragraph paragraph = new Paragraph(IUC);
                win_TalkWindow.rtb_ReviewMessage.Document.Blocks.Add(IUC);
                win_TalkWindow.rtb_ReviewMessage.ScrollToEnd();
            }
        }

        /// <summary>
        ///     向指定聊天窗口中附加本次聊天内容
        /// </summary>
        /// <param name="Total_Grid" type="System.Windows.Controls.Grid">
        ///     <para>
        ///         聊天内容总容器
        ///     </para>
        /// </param>
        /// <param name="inpackage" type="Hi_Baidu.Packet.InPacket.TalkInPacket.Total_TalkMessagePacket">
        ///     <para>
        ///         好友用户名
        ///     </para>
        /// </param>
        /// <param name="TalkSession" type="string">
        ///     <para>
        ///         本次会话标示
        ///     </para>
        /// </param>
        public static void AppendMessage(Grid Total_Grid, String FriendUsername, String TalkSession)
        {
            // 获取用户聊天窗口
            Win_TalkWindow win_TalkWindow = Globle.popWindowManager.GetMemberByKey(FriendUsername) as Win_TalkWindow;
            //存在这添加聊天信息
            if (win_TalkWindow != null)
            {
                Total_Grid.Tag = TalkSession;
                BlockUIContainer IUC = new BlockUIContainer(Total_Grid);
                //Paragraph paragraph = new Paragraph(IUC);
                win_TalkWindow.rtb_ReviewMessage.Document.Blocks.Add(IUC);
                win_TalkWindow.rtb_ReviewMessage.ScrollToEnd();
            }
        }

        /// <summary>
        ///     向指定聊天窗口中附加本次聊天内容
        /// </summary>
        /// <param name="Total_Grid" type="System.Windows.Controls.Grid">
        ///     <para>
        ///         聊天内容总容器
        ///     </para>
        /// </param>
        /// <param name="inpackage" type="Hi_Baidu.Packet.InPacket.TalkInPacket.Total_TalkMessagePacket">
        ///     <para>
        ///         好友用户名
        ///     </para>
        /// </param>
        /// <param name="TalkSession" type="string">
        ///     <para>
        ///         本次会话标示
        ///     </para>
        /// </param>
        public static void AppendMessage(Grid Total_Grid, Win_TalkWindow win_TalkWindow, String TalkSession)
        {
                Total_Grid.Tag = TalkSession;
                BlockUIContainer IUC = new BlockUIContainer(Total_Grid);
                //Paragraph paragraph = new Paragraph(IUC);
                win_TalkWindow.rtb_ReviewMessage.Document.Blocks.Add(IUC);
                win_TalkWindow.rtb_ReviewMessage.ScrollToEnd();
        }

        /// <summary>
        ///     附加聊天头部信息
        /// </summary>
        /// <param name="Total_StackPanel" type="System.Windows.Controls.StackPanel">
        ///     <para>
        ///         聊天信息总面板
        ///     </para>
        /// </param>
        /// <param name="inpackage" type="Hi_Baidu.Packet.InPacket.TalkInPacket.Total_TalkMessagePacket">
        ///     <para>
        ///         聊天信息包
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回附加头部后的聊天信息总面板
        /// </returns>
        public static Grid AppendHead(Grid Total_Grid, Total_TalkMessagePacket inpackage)
        {
            StackPanel SP_Header = new StackPanel();
            SP_Header.Orientation = Orientation.Horizontal;
            TextBlock TB_FriendName = new TextBlock();
            TYPE_UserMark userMark = Globle.userMarkManager.GetMemberByKey(inpackage.GetUsername()) as TYPE_UserMark;
            if (userMark != null)
            {
                TB_FriendName.Text = userMark.MarkName;
            }
            else
            {
                TB_FriendName.Text = inpackage.GetUsername();
            }
            TB_FriendName.Tag = inpackage.GetUsername();
            TB_FriendName.Margin = new Thickness(3, 3, 0, 3);
            TB_FriendName.Foreground = Brushes.Blue;
            TextBlock TB_SendTime = new TextBlock();
            TB_SendTime.Text = inpackage.TalkPackage.SendTime.ToShortTimeString();
            TB_SendTime.Foreground = Brushes.Blue;
            TB_SendTime.Margin = new Thickness(3, 3, 0, 3);
            SP_Header.Children.Add(TB_FriendName);
            SP_Header.Children.Add(TB_SendTime);
            Total_Grid.Children.Add(SP_Header);
            Grid.SetRow(SP_Header, 0);
            return Total_Grid;
        }

        /// <summary>
        ///     附加聊天头部信息
        /// </summary>
        /// <param name="Total_StackPanel" type="System.Windows.Controls.StackPanel">
        ///     <para>
        ///         聊天信息总面板
        ///     </para>
        /// </param>
        /// <param name="inpackage" type="Hi_Baidu.Packet.InPacket.TalkInPacket.Total_TalkMessagePacket">
        ///     <para>
        ///         聊天信息包
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回附加头部后的聊天信息总面板
        /// </returns>
        public static Grid AppendHead(Grid Total_Grid, String Username, String SendTime)
        {
            Friend friend = Globle.friendCollection.GetMemberByKey(Username) as Friend;
            StackPanel SP_Header = new StackPanel();
            SP_Header.Orientation = Orientation.Horizontal;
            TextBlock TB_FriendName = new TextBlock();
            if (friend != null)
            {
                TYPE_UserMark userMark = Globle.userMarkManager.GetMemberByKey(friend.Username) as TYPE_UserMark;
                if (userMark != null)
                {
                    TB_FriendName.Text = userMark.MarkName;
                }
                else
                {
                    TB_FriendName.Text = friend.Name;
                }
            }
            else
            {
                TB_FriendName.Text = "陌生人";
            }
            TB_FriendName.Margin = new Thickness(3, 3, 0, 3);
            TB_FriendName.Foreground = Brushes.Blue;
            TextBlock TB_SendTime = new TextBlock();
            TB_SendTime.Text = SendTime;
            TB_SendTime.Foreground = Brushes.Blue;
            TB_SendTime.Margin = new Thickness(3, 3, 0, 3);
            SP_Header.Children.Add(TB_FriendName);
            SP_Header.Children.Add(TB_SendTime);
            Total_Grid.Children.Add(SP_Header);
            Grid.SetRow(SP_Header, 0);
            return Total_Grid;
        }

        /// <summary>
        ///     附加超时的聊天头部信息
        /// </summary>
        /// <param name="Total_StackPanel" type="System.Windows.Controls.StackPanel">
        ///     <para>
        ///         聊天信息总面板
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回附加超时头部后的聊天信息总面板
        /// </returns>
        public static Grid AppendHead(Grid Total_Grid)
        {
            StackPanel SP_Header = new StackPanel();
            SP_Header.Orientation = Orientation.Horizontal;
            Image NotifyImg = new Image();
            NotifyImg.Source = new BitmapImage(new Uri("pack://application:,,,/SysImage/nt.png"));
            NotifyImg.Width = 14;
            NotifyImg.Height = 14;
            NotifyImg.Margin = new Thickness(3, 3, 0, 3);
            TextBlock TB_TimeOut = new TextBlock();
            TB_TimeOut.Text = "抱歉，由于网络原因，您发送的聊天信息可能无法到达。";
            TB_TimeOut.Margin = new Thickness(3, 3, 0, 3);
            TB_TimeOut.Foreground = Brushes.LightGray;
            SP_Header.Children.Add(NotifyImg);
            SP_Header.Children.Add(TB_TimeOut);
            Total_Grid.Children.Add(SP_Header);
            Grid.SetRow(SP_Header, 0);
            return Total_Grid;
        }

        /// <summary>
        ///     附加自身聊天头部信息
        /// </summary>
        /// <param name="Total_Grid" type="System.Windows.Controls.Grid">
        ///     <para>
        ///         聊天信息总面板
        ///     </para>
        /// </param>
        /// <param name="username" type="string">
        ///     <para>
        ///         自身昵称
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回附加头部后的聊天信息总面板
        /// </returns>
        public static Grid AppendMySelfHead(Grid Total_Grid, String username)
        {
            StackPanel SP_Header = new StackPanel();
            SP_Header.Orientation = Orientation.Horizontal;
            TextBlock TB_FriendName = new TextBlock();
            TB_FriendName.Text = username;
            TB_FriendName.Margin = new Thickness(3, 3, 0, 3);
            TB_FriendName.Foreground = Brushes.Green;
            TextBlock TB_SendTime = new TextBlock();
            TB_SendTime.Text = DateTime.Now.ToShortTimeString();
            TB_SendTime.Foreground = Brushes.Green;
            TB_SendTime.Margin = new Thickness(3, 3, 0, 3);
            SP_Header.Children.Add(TB_FriendName);
            SP_Header.Children.Add(TB_SendTime);
            Total_Grid.Children.Add(SP_Header);
            Grid.SetRow(SP_Header, 0);
            return Total_Grid;
        }

        public static Image ConstrueImage(Dictionary<String, String> Content, String TalkSession)
        {
            ImageExpender Img_Expender = null;
            Stream imageStream = null;
            System.Drawing.Bitmap bitmap = null;
            ProtocolFactory.ProtocolFactory.PictrueType PicType = (ProtocolFactory.ProtocolFactory.PictrueType)int.Parse(Content["PICTYPE"].Replace("\"", ""));
            switch (PicType)
            {
                //系统表情
                case ProtocolFactory.ProtocolFactory.PictrueType.Define:
                    Img_Expender = new ImageExpender();
                    Img_Expender.Stretch = Stretch.None;
                    Img_Expender.Visibility = System.Windows.Visibility.Visible;
                    imageStream = Application.GetResourceStream(new Uri(Content["SOURCE"].Replace("'", "").Replace("\"", ""), UriKind.Relative)).Stream;
                     bitmap = new System.Drawing.Bitmap(imageStream);
                    Img_Expender.Image = bitmap;
                    return Img_Expender;
                    break;
                //用户自定义
                case ProtocolFactory.ProtocolFactory.PictrueType.User:
                    //创建等待图像
                    Img_Expender = new ImageExpender();
                    Img_Expender.Stretch = Stretch.None;
                    Img_Expender.Visibility = System.Windows.Visibility.Visible;
                    //向用户请求未完成的图片 --> 需求：图片提取码
                    if (ChatProcessModel.RequestImage(Encoding.Default.GetString(Globle.user.DIC_USERINFO["USERNAME"]).Replace("\"", ""), Content["USERNAME"].Replace("\"", ""), Content["SOURCE"].Replace("\"", ""), TalkSession, Content["PID"].Replace("\"", "")))
                    {
                        imageStream = Application.GetResourceStream(new Uri(@"/SysImage/ImageLoading.gif", UriKind.Relative)).Stream;
                    }
                    else
                    {
                        imageStream = Application.GetResourceStream(new Uri(@"/SysImage/ImageError.gif", UriKind.Relative)).Stream;
                    }
                    bitmap = new System.Drawing.Bitmap(imageStream);
                    Img_Expender.Image = bitmap;
                    Img_Expender.Tag = Content["PID"].Replace("'", "");
                    return Img_Expender;
                    break;
            }
            return new Image();
        }

        public static TextBlock ConstrueText(Dictionary<String, String> Content)
        {
            TextBlock TB_TextMessage = new TextBlock();
            TB_TextMessage.Foreground = Brushes.Black;
            TB_TextMessage.FontSize = double.Parse(Content["SIZE"].Replace("\"",""));
            TB_TextMessage.FontFamily = new FontFamily(Content["FAMILY"].Replace("\"", ""));
            TB_TextMessage.Text = Content["VALUE"].Replace("(*Split*)", "|").Replace("(*CEqu*)", "=").Replace("(*Space*)", " ").Replace("\"","");
            return TB_TextMessage;
        }

        /// <summary>
        ///     向指定聊天窗口的输入框中打入用户选择的JPG图像
        /// </summary>
        /// <param name="win_TalkWindow" type="Hi_Baidu.Win_TalkWindow">
        ///     <para>
        ///         聊天窗口句柄
        ///     </para>
        /// </param>
        /// <param name="img" type="System.Windows.Controls.Image">
        ///     <para>
        ///         用户选中的图像
        ///     </para>
        /// </param>
        public static void AppendImage(Win_TalkWindow win_TalkWindow, Image img)
        {
            img.Stretch = Stretch.None;
            InlineUIContainer uiContainer = new InlineUIContainer(img);
            win_TalkWindow.rtb_TalkMessage.Document.Blocks.Add(new Paragraph(uiContainer));
        }

        /// <summary>
        ///      向指定聊天窗口的输入框中打入用户选择的GIF图像
        /// </summary>
        /// <param name="win_TalkWindow" type="Hi_Baidu.Win_TalkWindow">
        ///     <para>
        ///         聊天窗口句柄
        ///     </para>
        /// </param>
        /// <param name="img_Ex" type="WpfApplication1.ImageExpender">
        ///     <para>
        ///         用户选中的GIF动画对象
        ///     </para>
        /// </param>
        public static void AppendGif(Win_TalkWindow win_TalkWindow, ImageExpender img_Ex)
        {
            InlineUIContainer uiContainer = new InlineUIContainer(img_Ex);
            win_TalkWindow.rtb_TalkMessage.Document.Blocks.Add(new Paragraph(uiContainer));
        }

        /// <summary>
        ///     替换拼装好的图片到好友聊天窗口中的指定消息
        /// </summary>
        /// <param name="DetachImage" type="System.Drawing.Image">
        ///     <para>
        ///         图片
        ///     </para>
        /// </param>
        /// <param name="DetachImageCache" type="Hi_Baidu.ListType.DetachImage.TYPE_DETACH_IMAGE_MESSAGE">
        ///     <para>
        ///         分片图片缓存
        ///     </para>
        /// </param>
        public static void AppendDetachImageToUserTalkWindow(System.Drawing.Image DetachImage,TYPE_DETACH_IMAGE_MESSAGE DetachImageCache)
        {
            Win_TalkWindow win_TalkWindow = Globle.popWindowManager.GetMemberByKey(DetachImageCache.Username) as Win_TalkWindow;
            //找到对应的聊天窗口
            if (win_TalkWindow != null)
            {
                //开始分析该聊天窗口中的用户聊天信息内容
                FlowDocument document = win_TalkWindow.rtb_ReviewMessage.Document;
                //遍历文档顶级节点
                foreach (Block blk in document.Blocks)
                {
                    //当前对象是元素
                    if (blk is Paragraph)
                    {
                        Paragraph para = blk as Paragraph;
                        //判断元素类型 --> 是图像
                        foreach (Inline line in para.Inlines)
                        {
                            if (line is Run)
                            {
                                Run run = (line as Run);
                            }
                            else if (line is InlineUIContainer)
                            {
                                InlineUIContainer IUC = line as InlineUIContainer;
                                if (IUC.Child is ImageExpender)
                                {
                                    ImageExpender Img_Exp = IUC.Child as ImageExpender;
                                }
                                else if (IUC.Child is Image)
                                {
                                    Image Img = IUC.Child as Image;
                                }
                            }
                        }
                    }
                    else if(blk is BlockUIContainer)
                    {
                        BlockUIContainer blockUIContainer = blk as BlockUIContainer;
                        if (blockUIContainer.Child is Grid)
                        {
                            foreach (FrameworkElement item in (blockUIContainer.Child as Grid).Children)
                            {
                                if(item is WrapPanel)
                                {
                                    WrapPanel wrapPanel = item as WrapPanel;
                                    foreach (FrameworkElement talkitem in wrapPanel.Children)
                                    {
                                        if(talkitem is ImageExpender)
                                        {
                                            ImageExpender TempExpender = talkitem as ImageExpender;
                                            if (TempExpender.Tag != null && TempExpender.Tag.ToString().Replace("\"","") == DetachImageCache.PID)
                                            {
                                                TempExpender.Image = DetachImage;
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        ///     附加发送抖动请求失败的消息
        /// </summary>
        /// <param name="friend" type="Hi_Baidu.Entry.CollectionObject.Friend">
        ///     <para>
        ///         好友对象
        ///     </para>
        /// </param>
        public static void AppendSendShadowFail(Friend friend)
        {
            //直接提示
            Grid grid = new Grid();
            StackPanel sp = new StackPanel();
            sp.Orientation = System.Windows.Controls.Orientation.Horizontal;
            grid.Children.Add(sp);
            Image img = new Image();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/SysImage/Right.png"));
            img.Stretch = Stretch.Fill;
            img.Height = 16;
            img.Width = 16;
            img.Margin = new Thickness(5, 0, 5, 0);
            sp.Children.Add(img);
            TextBlock tb_Notify = new TextBlock();
            tb_Notify.Text = "您的好友不在线或隐身，因此您不能发送窗口抖动。";
            tb_Notify.Margin = new Thickness(0, 0, 0, 0);
            sp.Children.Add(tb_Notify);
            ChatViewModel.AppendMessage(grid, friend.Username, "");
        }

        /// <summary>
        ///     附加发送抖动请求成功的消息
        /// </summary>
        /// <param name="win_TalkWindow" type="Hi_Baidu.Win_TalkWindow">
        ///     <para>
        ///         聊天窗口
        ///     </para>
        /// </param>
        public static void AppendSendShadowSucessful(Win_TalkWindow win_TalkWindow, String NotifyText)
        {
            //直接提示
            Grid grid = new Grid();
            StackPanel sp = new StackPanel();
            sp.Orientation = System.Windows.Controls.Orientation.Horizontal;
            grid.Children.Add(sp);
            Image img = new Image();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/SysImage/Right.png"));
            img.Stretch = Stretch.Fill;
            img.Height = 16;
            img.Width = 16;
            img.Margin = new Thickness(5, 0, 5, 0);
            sp.Children.Add(img);
            TextBlock tb_Notify = new TextBlock();
            tb_Notify.Text = NotifyText;
            tb_Notify.Margin = new Thickness(0, 0, 0, 0);
            sp.Children.Add(tb_Notify);
            ChatViewModel.AppendMessage(grid, win_TalkWindow, "");
        }

        /// <summary>
        ///     触发指定聊天窗口的抖动效果
        /// </summary>
        /// <param name="win_TalkWindow" type="Hi_Baidu.Win_TalkWindow">
        ///     <para>
        ///         聊天窗口
        ///     </para>
        /// </param>
        public static void MakeWindowShadow(Win_TalkWindow win_TalkWindow)
        {
            //附加成功接收窗口抖动效果标示
            AppendSendShadowSucessful(win_TalkWindow, "接收到好友发送的窗口抖动。");
            ////////////////////////////////////////////////////////////////////////////////////////
            ///                     窗口抖动效果开始
            ////////////////////////////////////////////////////////////////////////////////////////
            WindowShadow = win_TalkWindow;
            timer_Action = new System.Timers.Timer();
            timer_Action.Interval = 200;
            timer_Action.Elapsed += new System.Timers.ElapsedEventHandler(timer_Action_Elapsed);
            timer_Action.Start();
            //播放音乐
            MusicPlayer.MusicPlayer.Play(Hi_Baidu.MusicPlayer.MusicPlayer.SongType.WINDOW_SHADOW);
        }

        static void timer_Action_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (ShadowCounter <= 2)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new DELEGATE_SHADOW(WindowShadowAction));
                ShadowCounter++;
            }
            else
            {
                ShadowCounter = 0;
                timer_Action.Stop();
                timer_Action.Dispose();
            }
        }

        private static void WindowShadowAction()
        {
            if (WindowShadow != null)
            {
                //得到窗口初始位置
                Point InitLocation = WindowShadow.PointToScreen(new Point(0, 0));
                WindowShadow.Top -= 5;
                WindowShadow.Left -= 5;
                WindowShadow.Top += 5;
                WindowShadow.Left += 5;
            }
        }
    }
}
